#include "sicasm.h"

/*********************************************************/
//OPTAB - Operation Code Table

struct OPFLD {
 char mnemonic[7];
 int  opcode;
 };

const OPFLD OPTAB[25] = {
	{ "ADD   ", 24 }, { "AND   ", 64 },
	{ "COMP  ", 40 }, { "DIV   ", 36 },
	{ "J     ", 60 }, { "JEQ   ", 48 },
	{ "JGT   ", 52 }, { "JLT   ", 56 },
	{ "JSUB  ", 72 }, { "LDA   ", 0  },
	{ "LDCH  ", 80 }, { "LDL   ", 8  },
	{ "LDX   ", 4  }, { "MUL   ", 32 },
	{ "OR    ", 68 }, { "RD    ", 216},
	{ "RSUB  ", 76 }, { "STA   ", 12 },
	{ "STCH  ", 84 }, { "STL   ", 20 },
	{ "STX   ", 16 }, { "SUB   ", 28 },
	{ "TD    ", 224}, { "TIX   ", 44 },
	{ "WD    ", 220 }
};

int opcodesearch(char *opcode)
{
 int i=0;
 while (i<=25)
  {
    if (!strcmp(opcode,OPTAB[i].mnemonic))
       return OPTAB[i].opcode;
    else i++;
  }
 return -1;
}

/******************************************************/
//SYMTAB - Symbol Table Class

/*
class SYMTAB {
 private:
 struct{
   char symbol[9];
   int addr;
   } symfield[MAXSYM];
 int lastentry;
 public:
  SYMTAB(void);
  int search(char *operand);
  void insert(char *label,int locctr);
};
*/
SYMTAB::SYMTAB(void)
{
  for(int i=0;i<MAXSYM;i++)
    {
      symfield[i].addr=0;
      strcpy(symfield[i].symbol,"        ");
    }
  lastentry=-1;
}

int SYMTAB::search(char *label)
{
 int i=0;
 while (i<=lastentry)
 {
  if (!strcmp(symfield[i].symbol,label))
   return symfield[i].addr;
  else i++;
 }
 return -1;
}

void SYMTAB::insert(char *label,int locctr)
{
 strcpy(symfield[++lastentry].symbol,label);
 symfield[lastentry].addr=locctr;
}

/*****************************************************/

